package com.example.activities;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

import com.example.activities.Module.Student;

public class AnotherActivity extends AppCompatActivity {

    private static final String tag = "MyAnotherTag";

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_another);

        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        int age = intent.getIntExtra("age", 0);
        Student student = (Student) intent.getSerializableExtra("student");

        TextView textView = findViewById(R.id.textViewReceive);
        textView.setText("name"+ name+ ",age"+ age+ ",student:"+ student.getName()+","+student.getAge());

        Button back = findViewById(R.id.back1);
        back.setOnClickListener(view -> {

            Log.v(tag, "back successfully");

            Intent intent1 = new Intent(AnotherActivity.this, MainActivity.class);
            intent1.putExtra("result", "返回成昆");
            setResult(0, intent);
            startActivity(intent1);
            finish();
        });

        Button back1 = findViewById(R.id.back2);
        back1.setOnClickListener(view -> {

            Log.v(tag, "back Failed");

            Intent intent2 = new Intent(AnotherActivity.this, MainActivity.class);
            intent2.putExtra("result", "返回失败！");
            startActivity(intent2);
            setResult(1, intent);
            finish();
        });
    }

}